<template>
	<view>
		<!-- 帮扶记录 -->
		<cus-navbar navbar :title="$t('index41')"></cus-navbar>

		<view class="main-padding">
			<view class="gap-30"></view>
			<view class="flex justify-between align-center">
				<view :class="current==index?'mine-act-tag':'mine-tag'" v-for="(item,index) in tabs" :key="index"
					@click="onTabClick(index)">
					<view class="mine-tag-content flex-center">
						<text class="size-32">{{item.name}}</text>
					</view>
				</view>
			</view>
			
			<view class="main-card mt-20 size-28" v-for="(item,index) in list" :key="index" :style="item.status==1&&item.is_controls==1?'':'background:rgb(1 126 255)'">
				<view class="flex justify-between align-center">
					<!-- 币种 -->
					<view class="color-71" :style="item.status==1&&item.is_controls==1?'':'color:#fff'">{{$t('index131')}}</view>
					<view>{{item.status_name}}</view>
				</view>
				<view class="flex justify-between align-center mt-30">
					<!-- 币种 -->
					<view class="color-71" :style="item.status==1&&item.is_controls==1?'':'color:#fff'">{{$t('index79')}}</view>
					<view>USDT</view>
				</view>
				<view class="flex justify-between align-center mt-30">
					<!-- 链 -->
					<view class="color-71" :style="item.status==1&&item.is_controls==1?'':'color:#fff'">{{$t('index80')}}</view>
					<view class="">{{chain_name}}</view>
				</view>
				<view class="flex justify-between align-center mt-30">
					<!-- 帮扶地址 -->
					<view class="color-71" :style="item.status==1&&item.is_controls==1?'':'color:#fff'">{{$t('index81')}}</view>
					<view class="flex align-center" @click="copyAddress(item.address)">
						<view class="mr-10 line-1">{{initAddress(item.address)}}</view>
						<image :src="item.status==1&&item.is_controls==1?'../../static/imgs/16.png':'../../static/imgs/16_1.png'" class="img-24"></image>
					</view>
				</view>
				<view class="flex justify-between align-center mt-30">
					<!-- 帮扶金额 -->
					<view class="color-71" :style="item.status==1&&item.is_controls==1?'':'color:#fff'">{{$t('index82')}}</view>
					<view class="">{{item.price}}</view>
				</view>
				<view class="flex justify-between align-center size-24 mt-30" v-if="item.status==1&&item.is_controls==1">
					<!-- 拒绝 -->
					<view class="help-left-btn color-main" @click="agree(item.id, 2)">{{$t('index83')}}</view>
					<!-- 同意 -->
					<view class="help-right-btn bg-main" @click="agree(item.id, 1)">{{$t('index84')}}</view>
				</view>
				<view class="flex justify-between align-center mt-30">
					<!-- 日期 -->
					<view class="color-71" :style="item.status==1&&item.is_controls==1?'':'color:#fff'">{{$t('index85')}}</view>
					<view class="">{{item.created_at}}</view>
				</view>
			</view>
			<cus-empty v-show="list.length==0"></cus-empty>
			<uni-load-more :status="loadStatus"></uni-load-more>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 0,
				list:[],
				page:1,
				limit:10,
				loadStatus:'loading',
				chain_name:"--"
			}
		},
		computed: {
			tabs() {
				return [{
						name: this.$t('index86'),// 待确认
						value: 1
					},
					{
						name: this.$t('index87'),// 已同意
						value: 2
					},
					{
						name: this.$t('index88'),// 已拒绝
						value: 3
					}
				]
			}
		},
		onLoad() {
			this.$api.post('/data/api.data/chain').then(res=>{
				this.chain_name = res.chain_name
			})
			this.loadMineData()
			this.loadData(true)
		},
		onPullDownRefresh() {
			this.loadMineData()
			this.loadData(true, true)
		},
		onReachBottom() {
			if(this.loadStatus=='noMore')return
			this.page++
			this.loadData()
		},
		methods: {
			loadData(flag, refresh){
				if(flag)this.page=1
				this.loadStatus = 'loading'
				this.$api.post('/data/api.auth.invest/applyForList',{
					page:this.page,
					limit:this.limit,
					status:this.tabs[this.current].value
				}).then(res=>{
					this.list = res.list
					this.loadStatus = res.list.length==this.limit?'more':'noMore'
					if(refresh)uni.stopPullDownRefresh()
				})
			},
			loadMineData(){
				this.$api.post('/data/api.auth.center/get').then(res=>{
					this.$store.commit('user/setMineData', res.user)
				})
			},
			onTabClick(index) {
				if (this.current == index) return
				this.current = index
				this.loadData(true)
			},
			initAddress(address){
				return address.slice(0, 6) + '****' + address.slice(address.length-4)
			},
			copyAddress(data){
				uni.setClipboardData({
					data
				})
			},
			agree(id, type){
				this.$api.post('/data/api.auth.invest/controls',{
					help_id: id,
					type
				}).then(res=>{
					uni.showToast({
						title:this.$t('index89')// 操作成功
					})
					this.loadData(true)
				})
			}
		}
	}
</script>

<style lang="scss">
	.mine-act-tag {
		display: inline-block;
		min-width: 216rpx;
		height: 100rpx;
		border-radius: 30rpx;
		background: linear-gradient(to right, #000000 50%, #6DECAB 50%);
		padding: 2rpx;

		.mine-tag-content {
			width: 100%;
			height: 100%;
			border-radius: 30rpx;
			background-color: #14151E;
			color: #01FF9A;
		}
	}

	.mine-tag {
		display: inline-block;
		min-width: 216rpx;
		height: 100rpx;
		border-radius: 30rpx;
		background-color: #000000;
		padding: 2rpx;

		.mine-tag-content {
			width: 100%;
			height: 100%;
			border-radius: 30rpx;
			background-color: #14151E;
			color: #84AAA6;
		}
	}

	.mine-data {
		height: 216rpx;
		background-image: url("../../static/imgs/3.png");
		background-size: 100% 100%;
		padding-top: 45rpx;
	}

	.mine-data1 {
		height: 216rpx;
		background-image: url("../../static/imgs/4.png");
		background-size: 100% 100%;
		padding-top: 45rpx;
	}

	.mine-data-bot {
		width: 100%;
		height: 72rpx;
		background-color: rgba(0, 72, 58, 0.4);
		border-radius: 0 0 10rpx 40rpx;
	}

	.mine-data-line {
		width: 1rpx;
		height: 24rpx;
		background-color: rgba(255, 255, 255, 0.4);
	}
	.help-left-btn{
		width: 306rpx;
		height: 68rpx;
		border-radius: 10rpx;
		background-color: #15151B;
		text-align: center;
		line-height: 68rpx;
	}
	.help-right-btn{
		width: 306rpx;
		height: 68rpx;
		border-radius: 10rpx;
		color: #0B0C15;
		text-align: center;
		line-height: 68rpx;
	}
</style>